package impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Keevu
 * Date: 22/08/11
 * Time: 18:01
 * To change this template use File | Settings | File Templates.
 */
public class SelectionSort extends AbstractSorter {

    public SelectionSort() {
        super(SorterType.SELECTION);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        for (int i = 0; i < ts.size(); i++) {
            int min = i;
            for (int j = i + 1; j < ts.size(); j++) {
                if (greater(tComparator, ts, min, j)) {
                    min = j;
                }
            }
            swap(ts, i, min);
        }
    }
}
